package com.horizon.api;

import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system")
public class SystemApi {

    @GetMapping("/getLockedApps")
    public JSONArray getLockedApps() {
        return JSONUtil.parseArray("[\"baseService\", \"devPlatform\"]");
    }

    @GetMapping("/getMenus")
    public ResponseEntity<JSONArray> getMenus(@RequestParam String appCode) {
        JSONArray jsonArray = new JSONArray();
        if ("baseService".equals(appCode)) {
            jsonArray = JSONUtil.parseArray("[\n" +
                    "    {\n" +
                    "        \"path\": \"person\",\n" +
                    "        \"icon\": \"user\",\n" +
                    "        \"i18n\": {\n" +
                    "            \"name\": {\n" +
                    "                \"zh-CN\": \"人员管理\"\n" +
                    "            }\n" +
                    "        },\n" +
                    "        \"fdId\": \"3b81992a560b4112ab372788f2c9aac9\"\n" +
                    "    },\n" +
                    "    {\n" +
                    "        \"icon\": \"apartment\",\n" +
                    "        \"i18n\": {\n" +
                    "            \"name\": {\n" +
                    "                \"zh-CN\": \"组织管理\"\n" +
                    "            }\n" +
                    "        },\n" +
                    "        \"children\": [\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"行政组织\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"path\": \"xzzz\",\n" +
                    "                \"fdId\": \"db9c782524a64709af459aad9e69b51d\"\n" +
                    "            },\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"组织场景化\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"children\": [\n" +
                    "                    {\n" +
                    "                        \"path\": \"jtzdpz\",\n" +
                    "                        \"i18n\": {\n" +
                    "                            \"name\": {\n" +
                    "                                \"zh-CN\": \"监听字段配置\"\n" +
                    "                            }\n" +
                    "                        },\n" +
                    "                        \"fdId\": \"74c9449e084141db89c984dcb98d65a9\"\n" +
                    "                    },\n" +
                    "                    {\n" +
                    "                        \"path\": \"sjgzpz\",\n" +
                    "                        \"i18n\": {\n" +
                    "                            \"name\": {\n" +
                    "                                \"zh-CN\": \"数据规则配置\"\n" +
                    "                            }\n" +
                    "                        },\n" +
                    "                        \"fdId\": \"e62f4727236e4c77be4d6d91b5e73316\"\n" +
                    "                    },\n" +
                    "                    {\n" +
                    "                        \"path\": \"wwzz\",\n" +
                    "                        \"i18n\": {\n" +
                    "                            \"name\": {\n" +
                    "                                \"zh-CN\": \"外围组织\"\n" +
                    "                            }\n" +
                    "                        },\n" +
                    "                        \"fdId\": \"27b1226205e94377bd83d7bbad2b0dd8\"\n" +
                    "                    },\n" +
                    "                    {\n" +
                    "                        \"path\": \"ydyys\",\n" +
                    "                        \"i18n\": {\n" +
                    "                            \"name\": {\n" +
                    "                                \"zh-CN\": \"一对一映射\"\n" +
                    "                            }\n" +
                    "                        },\n" +
                    "                        \"fdId\": \"8be3613c911049e482838be757b915ec\"\n" +
                    "                    },\n" +
                    "                    {\n" +
                    "                        \"path\": \"tsys\",\n" +
                    "                        \"i18n\": {\n" +
                    "                            \"name\": {\n" +
                    "                                \"zh-CN\": \"特殊映射\"\n" +
                    "                            }\n" +
                    "                        },\n" +
                    "                        \"fdId\": \"d0fc2c69f9ea4eadb9c0fe0db87338f4\"\n" +
                    "                    },\n" +
                    "                    {\n" +
                    "                        \"path\": \"mrjzgs\",\n" +
                    "                        \"i18n\": {\n" +
                    "                            \"name\": {\n" +
                    "                                \"zh-CN\": \"默认记账公司\"\n" +
                    "                            }\n" +
                    "                        },\n" +
                    "                        \"fdId\": \"905e51d662514177ac591c1db5696b80\"\n" +
                    "                    }\n" +
                    "                ],\n" +
                    "                \"fdId\": \"cc1e5417ea3c406c931a570f1a4782f0\"\n" +
                    "            }\n" +
                    "        ],\n" +
                    "        \"fdId\": \"c68e2a09d7104c68b94c500764afed37\"\n" +
                    "    },\n" +
                    "    {\n" +
                    "        \"icon\": \"team\",\n" +
                    "        \"i18n\": {\n" +
                    "            \"name\": {\n" +
                    "                \"zh-CN\": \"角色管理\"\n" +
                    "            }\n" +
                    "        },\n" +
                    "        \"children\": [\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"角色\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"path\": \"js\",\n" +
                    "                \"fdId\": \"1e014b172cb14112bee30ad266ace222\"\n" +
                    "            },\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"岗位\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"path\": \"gw\",\n" +
                    "                \"fdId\": \"4f67ca4a1943435ca21e53131f04f4b5\"\n" +
                    "            },\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"虚拟岗\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"path\": \"xng\",\n" +
                    "                \"fdId\": \"95f44b69745e4b388adb98a349dd58cd\"\n" +
                    "            }\n" +
                    "        ],\n" +
                    "        \"fdId\": \"84bd01f52a2c493a9496407439554c78\"\n" +
                    "    },\n" +
                    "    {\n" +
                    "        \"icon\": \"solution\",\n" +
                    "        \"i18n\": {\n" +
                    "            \"name\": {\n" +
                    "                \"zh-CN\": \"权限管理\"\n" +
                    "            }\n" +
                    "        },\n" +
                    "        \"children\": [\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"管理员\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"path\": \"gly\",\n" +
                    "                \"fdId\": \"18172afb5b5f466b9c770795818c708b\"\n" +
                    "            },\n" +
                    "            {\n" +
                    "                \"i18n\": {\n" +
                    "                    \"name\": {\n" +
                    "                        \"zh-CN\": \"用户授权\"\n" +
                    "                    }\n" +
                    "                },\n" +
                    "                \"path\": \"yhsq\",\n" +
                    "                \"fdId\": \"1343d76d23b24478a2e140615f914815\"\n" +
                    "            }\n" +
                    "        ],\n" +
                    "        \"fdId\": \"ed54671cfad741699b169047dd6709c9\"\n" +
                    "    }\n" +
                    "]");
        } else if ("devPlatform".equals(appCode)) {
            jsonArray = JSONUtil.parseArray("[\n" +
                    "      {\n" +
                    "      fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                    "        icon: \"\",\n" +
                    "        i18n: {\n" +
                    "          name: {\n" +
                    "            \"zh-CN\": \"云管理\",\n" +
                    "          },\n" +
                    "        },\n" +
                    "      },\n" +
                    "      {\n" +
                    "      fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                    "        icon: \"\",\n" +
                    "        i18n: {\n" +
                    "          name: {\n" +
                    "            \"zh-CN\": \"表单管理\",\n" +
                    "          },\n" +
                    "        },\n" +
                    "      },\n" +
                    "    ]");
        }

        System.out.println(jsonArray);
        return new ResponseEntity<>(jsonArray, HttpStatus.OK);
    }

    @RequestMapping(value = "/lockApp", method = RequestMethod.GET)
    public ResponseEntity lockApp(@RequestBody String appCode, @RequestBody Boolean lock) {
        System.out.println(appCode);
        System.out.println(lock);
        return new ResponseEntity(null, HttpStatus.OK);
    }

    @RequestMapping(value = "/getCloudApps", method = RequestMethod.GET)
    public ResponseEntity<JSONArray> getCloudApps() {
        JSONArray jsonArray = JSONUtil.parseArray("[\n" +
                "    {\n" +
                "      fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                "      code: \"SYS\",\n" +
                "      picture: \"\",\n" +
                "      i18n: {\n" +
                "        name: {\n" +
                "          \"zh-CN\": \"系统服务云\",\n" +
                "          \"en-US\": \"System Service Cloud\",\n" +
                "        },\n" +
                "      },\n" +
                "      children: [\n" +
                "        {\n" +
                "          fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                "          code: \"baseData\",\n" +
                "          home: \"baseData\",\n" +
                "          i18n: {\n" +
                "            name: {\n" +
                "              \"zh-CN\": \"基础资料\",\n" +
                "            },\n" +
                "            description: {\n" +
                "              \"zh-CN\": \"主数据、公共数据\",\n" +
                "            },\n" +
                "          },\n" +
                "        },\n" +
                "        {\n" +
                "          fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                "          code: \"baseService\",\n" +
                "          home: \"baseService\",\n" +
                "          i18n: {\n" +
                "            name: {\n" +
                "              \"zh-CN\": \"基础服务\",\n" +
                "              \"en-US\": \"Basic services\",\n" +
                "            },\n" +
                "            description: {\n" +
                "              \"zh-CN\": \"组织架构、人员、岗位等\",\n" +
                "              \"en-US\": \"Organizational structure, personnel, positions, etc.\",\n" +
                "            },\n" +
                "          },\n" +
                "        },\n" +
                "        {\n" +
                "          fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                "          code: \"sysManage\",\n" +
                "          home: \"sysManage\",\n" +
                "          i18n: {\n" +
                "            name: {\n" +
                "              \"zh-CN\": \"系统管理\",\n" +
                "            },\n" +
                "            description: {\n" +
                "              \"zh-CN\": \"网络互斥、操作日志、用户监控\",\n" +
                "            },\n" +
                "          },\n" +
                "        },\n" +
                "        {\n" +
                "          fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                "          code: \"devPlatform\",\n" +
                "          home: \"devPlatform\",\n" +
                "          i18n: {\n" +
                "            name: {\n" +
                "              \"zh-CN\": \"开发平台\",\n" +
                "              \"en-US\": \"Development Platform\",\n" +
                "            },\n" +
                "            description: {\n" +
                "              \"zh-CN\": \"表单设计器、流程设计器等\",\n" +
                "              \"en-US\": \"Form designer, process designer, etc.\",\n" +
                "            },\n" +
                "          },\n" +
                "        },\n" +
                "        {\n" +
                "          fdId: " + IdUtil.fastSimpleUUID() + ",\n" +
                "          code: \"configTool\",\n" +
                "          home: \"configTool\",\n" +
                "          i18n: {\n" +
                "            name: {\n" +
                "              \"zh-CN\": \"配置工具\",\n" +
                "            },\n" +
                "            description: {\n" +
                "              \"zh-CN\": \"打印和引入引出模板、单据类型\",\n" +
                "            },\n" +
                "          },\n" +
                "        },\n" +
                "      ],\n" +
                "    },\n" +
                "  ]");

        System.out.println(jsonArray);
        return new ResponseEntity<>(jsonArray, HttpStatus.OK);
    }

    @GetMapping("/getMotto")
    public ResponseEntity<String> getMotto() {
        String[] strs = new String[]{"故事和酒，淘宝都有", "千与千寻中最励志的话：不要吃太胖哦，会被杀掉的", "甘愿自卑，就只能沉沦下去；不肯自卑，就会产生无穷的动力", "让我们放弃前行的，到底是懦弱还是满足", "门外世界，门里是家"};
        Double index = Math.floor(Math.random() * strs.length);
        return new ResponseEntity<>(strs[index.intValue()], HttpStatus.OK);
    }
}
